<?php

namespace app\controllers;

use Yii;

use yii\web\Controller;

use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use yii\db\ActiveRecord;
use yii\data\SqlDataProvider;
use app\models\IntegratedqueryModel;
use app\models\IntegratedquerySearch;
use app\models\TmptableModel;
use yii\helpers\Url;


/**
 * 综合查询
 * 
 */
class IntegratedqueryController extends Controller
{
	
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
        		'access' => [
        				'class' => AccessControl::className(),
        				'only' => ['index','logout'],
        				'rules' => [
        						[
        								'actions' => ['index','logout'],
        								'allow' => true,
        								'roles' => ['manager'],
        						],
        				],
        		],
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['POST'],
                ],
            ],
        ];
    }
    

    /**
     * 综合查询 index.php
     * @return mixed
     */
    public function actionIndex()
    {    	
//     	$sql='TRUNCATE TABLE tmptable';
//     	$sql2='SELECT p.stu_id,p.stu_name,p.sex,p.card_id,p.used_name,p.nation,p.political,p.address nativeplace,p.religion,p.height,p.maritial_status,p.blood_type,p.telephone,p.qq,p.blank,p.blank_num,s.enroll_time,
// s.stu_type,s.major_name,s.class_name,s.status,d.dorm_area,d.dormitory,d.dorm_num,d.leader,f.address,f.recipient,f.postal_code,f.economic_status,f.load FROM personinfo p LEFT JOIN schoolinfo s ON p.stu_id=s.stu_id LEFT JOIN dorminfo d ON d.stu_id=p.stu_id LEFT JOIN familyinfo f ON f.stu_id=p.stu_id';
    	
//     	$tableName=TmptableModel::tableName();
//     	$field=['stu_id','stu_name','sex','card_id','used_name','nation','political','nativeplace','religion','height','maritial_status','blood_type','telephone','qq','blank','blank_num','enroll_time',
//     			'stu_type','major_name','class_name','status','dorm_area','dormitory','dorm_num','leader','address','recipient','postal_code','economic_status','load'];
    	 
//     	/**
//     	  * 清空临时表Tmptable
//     	  */
//      	\Yii::$app->db->createCommand($sql)->execute();
//      	/**
//      	 * 获取综合查询的数据
//      	 */
//     	$data=IntegratedqueryModel::findBySql($sql2)->asArray()->all();
//     	/**
//     	 * 批量插入 临时表Tmptable中
//     	 * @var Ambiguous $totalnum
//     	 */
//     	$totalnum = Yii::$app->db->createCommand()->batchInsert($tableName,$field,$data)->execute();
    	
//     	//跳转到临时表页面
//     	return $this->redirect(\Yii::$app->urlManager->baseUrl.'/tmptable/index');

    }

}
